package org.fastsyncer.manager.listener.mysql.binlog.impl.parser;

import java.io.IOException;

import org.fastsyncer.manager.listener.mysql.binlog.BinlogEventV4Header;
import org.fastsyncer.manager.listener.mysql.binlog.BinlogParserContext;
import org.fastsyncer.manager.listener.mysql.binlog.impl.event.IntvarEvent;
import org.fastsyncer.manager.listener.mysql.common.glossary.UnsignedLong;
import org.fastsyncer.manager.listener.mysql.io.XInputStream;

public class IntvarEventParser extends AbstractBinlogEventParser {

	public IntvarEventParser() {
		super(IntvarEvent.EVENT_TYPE);
	}

	public void parse(XInputStream is, BinlogEventV4Header header, BinlogParserContext context)
	throws IOException {
		final IntvarEvent event = new IntvarEvent(header);
		event.setBinlogFilename(context.getBinlogFileName());
		event.setType(is.readInt(1));
		event.setValue(UnsignedLong.valueOf(is.readLong(8)));
		context.getEventListener().onEvents(event);
	}
}
